package lock;

import org.springframework.http.converter.json.GsonBuilderUtils;

import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: Yangu
 * @Created time: 2021/1/11 11:50
 * @Description :
 */
public class ReentrantLockTest {
    private static Lock reentrantLock = new ReentrantLock();
    public static void lockTest() throws InterruptedException {
        reentrantLock.lock();
        Thread.sleep(1000L);
        System.out.println(Thread.currentThread().getName() + "--------test");
        reentrantLock.unlock();
    }

    public static void main(String[] args) throws InterruptedException {
//        lockTest();
        for(int i=0; i<2; i++) {
            new Thread(() -> {
                try {
                    lockTest();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }

//        Executors.newFixedThreadPool()
    }
}
